/* This file runs all the study-specific analysis do files to create 
study-specific results data files (.dta)
*/

cd ../AnalysisStudies

foreach folder in KN NORC {
	cd `folder'
	
	local subdirs : dir "." dirs "*"
	di `"`subdirs'"'
	foreach subdir in `subdirs' {
		cd `subdir'
		local do_files: dir "." files "*.do"
		display `"`do_files'"'
		foreach do_file in `do_files' {
			display "Running do-file: `do_file'"
			do `do_file'
		}
		local dta_files: dir "." files "*-results.dta"
		display `"`dta_files'"'
		foreach dta_file in `dta_files' {
			copy `dta_file' ../../results/`dta_file', replace
		}
		cd ..
	}
	cd ..
}
	
cd results

local dta_files: dir "." files "*-results.dta"

local firstfile "yes"
foreach dta_file in `dta_files' {
	if "`firstfile'" == "yes" {
		local firstfile "no"
		use `dta_file', clear
	}
	else {
		append using `dta_file'
	}
}

	rename num hyp_num
	rename type typeoftest

	
sa "../../Metadata/Hypotheses_results.dta", replace

cd ../../Script
